package com.hcg.initproject.service.impl;

import com.alibaba.fastjson.JSON;
import com.hcg.initproject.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("userService")
@Slf4j
public class UserServiceImpl implements UserService {

    @Value("${name}")
    private String name;
    @Value("${age}")
    private String age;
    @Override
    @Async
    public String orderAndSendMSG() {
        /*log.info("2");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("3");
        return "baby";*/
       new Thread(new Runnable() {
           @Override
           public void run() {
               log.info("2");
               try {
                   Thread.sleep(4000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               log.info("3");
//               return "baby";
           }
       }).start();
       return null;
    }

    @Override
    public String setValue() {
        Map<String,String> map = new HashMap<>();
        map.put(name,age);
        return JSON.toJSONString(map);
    }

}
